package com.tian.controller.user.api;

import com.tian.common.util.CommonResult;
import com.tian.dto.user.LicensePlateInfoListRespDto;
import com.tian.service.user.LicensePlateInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * {@code @description:} 城市车牌前缀信息
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-06-06 21:15
 * {@code @version:} 1.0
 */
@RestController
@RequestMapping("/user/license")
@Api(value = "汽车牌照前缀信息接口",tags = "汽车牌照前缀信息")
public class LicensePlateInfoController {

    @Resource
    private LicensePlateInfoService licensePlateInfoService;

    @GetMapping("/initData")
    public void initData() {
        // 初始化数据
        try {
            licensePlateInfoService.initData();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/all")
    @ApiOperation(value = "查询所有汽车牌照前缀信息信息列表")
    public CommonResult<LicensePlateInfoListRespDto> allLicensePlateInfo() {
        return licensePlateInfoService.getLicensePlateInfo();
    }

    @GetMapping("/list")
    @ApiOperation(value = "按照省份查询所有汽车牌照前缀信息信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="provinceCode",value="省份code",required = true,dataType = "String")
    })
    public CommonResult<LicensePlateInfoListRespDto> getLicensePlateInfoByProvinceCode(@RequestParam("provinceCode") String provinceCode) {
        return licensePlateInfoService.getLicensePlateInfoByProvinceCode(provinceCode);
    }
}
